<%--
  Created by IntelliJ IDEA.
  User: ZhuChunXiao
  Date: 2017/5/23
  Time: 14:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
  String _id=request.getParameter("_");
%>

<div class="row">
  <div class="col-lg-12">
    <div class="panel">
      <div class="panel-heading header">
        <h3 class="panel-title" id="title">员工调动申请表</h3>
      </div>

      <!-- BASIC FORM ELEMENTS -->
      <!--===================================================-->
      <form id="form_transfer_input" class="panel-body form-horizontal form-padding">
        <input type="hidden" name="keyId" id="keyId" value="${transfer.id}" />
        <input type="hidden" name="parentId" id="parentId" value="${parentId}" />
        <input type="hidden" name="curDutyId" id="curDutyId" value=""/>

        <div class="form-group">
          <label class="col-md-2 control-label">用人性质<i class="fa fa-asterisk txt-color-red"></i></label>
          <div class="col-md-6">
            <input disabled type="text" id="nature" name="nature" class="form-control" value="${personnelInfo.personnelUse.nature==1?"正式":"试用"}">
          </div>
        </div>

        <div class="form-group">
          <label class="col-md-2 control-label">调动员工<i class="fa fa-asterisk txt-color-red"></i></label>
          <div class="col-md-6">
            <input disabled type="text" id="name" name="name" class="form-control" value="${personnelInfo.name}">
          </div>
        </div>

        <div class="form-group">
          <label class="col-md-2 control-label">调动原因<i class="fa fa-asterisk txt-color-red"></i></label>
          <div class="col-md-6">
            <input type="text" id="reason" name="reason" class="form-control" placeholder="请输入调动原因" value="${transfer.reason}">
          </div>
        </div>

        <div class="form-group">
          <label class="col-md-2 control-label">
              <a href="javascript:void(0);" onclick="fn_departments_dialog_select('n','deptName','deptId')" style="color: #0a6dbd">部门</a>
            <i class="fa fa-asterisk txt-color-red"></i>
          </label>
          <div class="col-md-2">
            <input type="text" id="deptName" name="deptName" class="form-control" placeholder="请选择调往部门" disabled value="${transfer.department.name}">
            <input type="hidden" id="deptId" name="deptId" value="${transfer.department.id}">
          </div>

          <label class="col-md-2 control-label">
              <a href="javascript:void(0);" onclick="fn_posts_dialog_select('n',$('#deptId').val(),'postName','postId')" style="color: #0a6dbd">岗位</a>
            <i class="fa fa-asterisk txt-color-red"></i>
          </label>
          <div class="col-md-2">
            <input type="text" id="postName" name="postName" class="form-control" placeholder="请选择调往岗位" disabled value="${transfer.post.name}">
            <input type="hidden" id="postId" name="postId" value="${transfer.post.id}">
          </div>
        </div>

        <div class="form-group div-Hidden">
          <label class="col-md-2 control-label">原薪资<i class="fa fa-asterisk txt-color-red"></i></label>
          <div class="col-md-2">
            <input disabled type="text" class="form-control" id="oldSalary" name="oldSalary" value="${personnelInfo.personnelUse.salary}" />
          </div>
          <label class="col-md-2 control-label">调动后薪资<i class="fa fa-asterisk txt-color-red"></i></label>
          <div class="col-md-2">
            <input type="number" class="form-control" id="newSalary" name="newSalary" placeholder="请输入调动后薪资" value="${transfer.newSalary}" />
          </div>
        </div>


        <div class="form-group">
          <label class="col-md-2 control-label">提交人</label>
          <div class="col-md-2">
            <p class="form-control-static">${transfer.creater.name}</p>
          </div>
          <label class="col-md-2 control-label">提交日期</label>
          <div class="col-md-2">
            <p class="form-control-static"><fmt:formatDate pattern="yyyy-MM-dd" value="${transfer.createTime}" /></p>
          </div>
        </div>

        <div class="panel-footer">
          <a class="btn btn-default" id="apply-re-common" href="javascript:void(0)">
            <i class="fa fa-lg fa-mail-reply"></i> 返回
          </a>
          <a class="btn btn-success" id="btn-save-common" href="javascript:void(0);"><i class="fa fa-lg fa-download"></i> 保存 </a>
          <c:if test="${transfer==null || transfer.processState=='Draft'}">
            <a class="btn btn-warning" id="btn-commit-common" href="javascript:void(0);"><i class="fa fa-upload"></i> 提交 </a>
          </c:if>
          <c:if test="${transfer!=null && transfer.processState=='Backed'}">
            <a class="btn btn-warning" id="btn-recommit-common" href="javascript:void(0);"><i class="fa fa-upload"></i> 再提交 </a>
          </c:if>
        </div>
        
      </form>
      <!--===================================================-->
      <!-- END BASIC FORM ELEMENTS -->
      
    </div>
  </div>
</div>

<script>
  var index = "${index}";
  var todo = "${todo}";
  var remind = "${remind}";
  var record = "${record}";
  var draft =  "${draft}";

  $(function(){
    var pdata= {
      keyId:$("#keyId").val(),
      entityName:"com.fz.us.oa.core.entity.com.Transfer"
    };
    multiDuty(pdata);
//    fn_dispatch_input_validate()
  });

  // 部门选择框
  function fn_departments_dialog_select(isMulti,nameField,idField) {
    __open_dialog_select('选择部门', '<%=path%>/main/department/dialog?multi='+isMulti, function (dialogRef) {
      var callback = function (data) {
        if (data) {
          dialogRef.close();

          // 获取 user
          $('#'+idField).val(data.ids);
          $('#'+nameField).val(data.names);
        } else {
          dialogRef.enableButtons();
        }
      };
      fn_dialog_departments_select(callback);
    });
  }

  // 岗位选择框
  function fn_posts_dialog_select(isMulti,deptId,nameField,idField) {
    if($('#deptId').val()!=""&&$('#deptId').val()!=null){
      __open_dialog_select('选择岗位', '<%=path%>/com/personnelInfo/dialog?departmentId='+deptId+"&multi="+isMulti, function (dialogRef) {
        var callback = function (data) {
          if (data) {
            dialogRef.close();

            // 获取 user
            $('#'+idField).val(data.ids);
            $('#'+nameField).val(data.names);
          } else {
            dialogRef.enableButtons();
          }
        };
        fn_dialog_posts_select(callback);
      });
    }else{
      alert("请先选择部门");
    }

  }

  //校验
  function infoValidate() {
    var tmp = "";

    tmp = $("input#reason").val();
    if(!tmp){
      __toastr_error("请输入调动原因！");
      return false;
    }

    tmp = $("input#deptName").val();
    if(!tmp){
      __toastr_error("请选择部门！");
      return false;
    }

    tmp = $("input#postName").val();
    if(!tmp){
      __toastr_error("请选择岗位！");
      return false;
    }

    tmp = $("input#newSalary").val();
    if(!tmp){
      __toastr_error("请输入调动后薪资！");
      return false;
    }

    return true;
  }

  //保存
  $("#btn-save-common").click(
          function(e) {
            __confirm_dialog("提示：","确定保存吗？",
                    function () {
                      __form_save("form_transfer_input", "<%=path%>/com/transfer/save",function(){
                        $("#apply-re-common").trigger("click");
                      });
                    }
            )
          }
  );

  //提交
  $("#btn-commit-common,#btn-recommit-common").click(
          function(e) {
            var $valid = infoValidate();
//                console.log("v:"+$valid);
            if(!$valid) return false;

            __confirm_dialog("提示：","提交后填写资料不得修改，请确认是否进行提交？",
                    function () {
                      __form_save("form_transfer_input", "<%=path%>/com/transfer/submit",function(){
                        $("#apply-re-common").trigger("click");
                      });
                    }
            )
          }
  );

  //返回视图
  $("#apply-re-common").click(function(){
    if(index==1){
      loadURL("menu/dashboard",$('#page-content'));
    }else if(todo==1){
      loadURL("menu/toDo",$('#page-content'));
    }else if(remind==1){
      loadURL("menu/remind",$('#page-content'));
    }else if(record==1){
      loadURL("menu/taskRecord?type=1",$('#page-content'));
    }else if(record==2){
      loadURL("menu/taskRecord?type=2",$('#page-content'));
    }else if(draft==1){
      loadURL("menu/draft",$('#page-content'));
    }else{
      returnToHashUrl()
    }
  });


</script>